package cn.song.logread;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Log Read 应用程序
 *
 * @author SongRenShuo
 * @date 2025/03/16
 */
@Slf4j
@SpringBootApplication
public class LogReadApplication {


    public static void main(String[] args) throws UnknownHostException {
        Environment env = SpringApplication.run(LogReadApplication.class, args).getEnvironment();
        String active = env.getProperty("active");
        if (!"dev".equals(active)) {
            return;
        }

        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        path = path != null ? path : "/";

        log.info("项目启动成功...");
        log.info("==========首次使用,请先修改配置文件中的系统信息与账户信息==========");
        log.info("项目访问地址：http://{}:{}{}login", ip, port, path);

        // 启动加载指定页面
        try {
            // 可以指定自己的路径
            Runtime.getRuntime().exec("cmd   /c   start   " + "http://" + ip + ":" + port + "/login");
        } catch (Exception ex) {
            log.error("启动加载指定页面失败", ex);
        }
    }

}
